<?php

namespace Controller\Install;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;

class InstallLoginCSP implements ControllerProviderInterface {
    public function connect(Application $app) {
        $controllers = $app ['controllers_factory'];
        $controllers->match ( '/', function (Application $app) {
            
            $data = array (
                            'user' => 'Your username',
                            'pass' => 'Your password' 
            );
            
            $form = $app ['form.factory']->createBuilder ( 'form', $data )->add ( 'user' )->add ( 'pass' )->getForm ();
            
            // $form->handleRequest ( $request );
            
            if ($form->isValid ()) {
                $data = $form->getData ();
                
                // do something with the data
                
                // redirect somewhere
                return $app->redirect ( '...' );
            }
            
            // Render
            return $app ['twig']->render ( "install/default.twig", array (
                            'form' => $form->createView () 
            ) );
        }, 'GET|POST' );
        
        return $controllers;
    }
}